cmake_minimum_required(VERSION 3.20.0)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 17)

if (NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
    message("Setting default build type to Release")
endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

project(server VERSION 0.0.1 LANGUAGES C CXX)

include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_SOURCE_DIR}/3rd/include)
include_directories(${PROJECT_SOURCE_DIR}/hyperlpr/include)

find_package(fmt REQUIRED)
find_package(OpenCV CONFIG REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(Boost REQUIRED COMPONENTS uuid)

file(GLOB_RECURSE all_srcs ./src/*.cpp)

add_executable(main ${all_srcs})
add_subdirectory(hyperlpr)
add_subdirectory(3rd)

if (PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
    file(GLOB test_sources test/*.cpp)
    foreach(path ${test_sources})
        get_filename_component(name ${path} NAME_WE)
        add_executable(${name} ${path})
        target_link_libraries(${name} PRIVATE fmt::fmt)
        set_target_properties(${name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test)
    endforeach()
endif()

set_target_properties(main PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

target_link_libraries(main PRIVATE fmt::fmt)
target_link_libraries(main PRIVATE Boost::uuid)
target_link_libraries(main PRIVATE ${OpenCV_LIBS})
target_link_libraries(main PRIVATE hyperlpr)
target_link_libraries(main PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries(main PRIVATE 3rd)